package com.xoms.pad.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xoms.pad.model.OrderBean;
import com.xoms.pad.model.ProOrderBean;
import com.xoms.pad.persist.dao.OrderDao;
import com.xoms.util.StringUtil;


@Repository
public class OrderImpl extends BaseImpl implements OrderDao {

	final String NAME_SPACE = NAME_SPACE_HEADER + ".OrderMapper";

	@Override
	public int insert(OrderBean bean) {
		return sqlSessionTemplate.insert(NAME_SPACE + ".insert", bean);
	}

	@Override
	public int selectCount() {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount");
	}

	@Override
	public List<OrderBean> selectList(String accId ,String oid ,int sendStatus,int status,int orderType,int page, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(oid)) {
			params.put("oid", oid);
		}
		if (!StringUtil.isEmpty(Integer.toString(sendStatus))) {
			params.put("sendStatus", sendStatus);
		}
		params.put("status", status);
		
		if (!StringUtil.isEmpty(accId)) {
			params.put("accId", accId);
		}
		if (!StringUtil.isEmpty(Integer.toString(orderType))) {
			params.put("orderType", orderType);
		}
		params.put("start", page * pageSize);
		params.put("length", pageSize);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", params);
	}

	@Override
	public List<ProOrderBean> selectOrderProList(String oid) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtil.isEmpty(oid)) {
			params.put("oid", oid);
		}
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectOrderProList", params);
	}

	@Override
	public int selectModifyOrder(String oid, String payType, String isHand, String roomId,
			String handRoomId, String payStatus) {
		
		Map<String, Object> params = new HashMap<String, Object>();
			params.put("oid", oid);
			params.put("payType", payType);
			params.put("isHand", isHand);
			params.put("roomId", roomId);
			params.put("handRoomId", handRoomId);
			params.put("payStatus", payStatus);
		
		return sqlSessionTemplate.update(NAME_SPACE + ".updateOrder", params);
	}

	@Override
	public OrderBean selectByOrderNo(String orderNo) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("orderNo", orderNo);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectByOrderNo", params);
	}

}
